import { RequestHandler } from 'express';
import { req_info_cur_user_function_create } from '../Classes/cla_req_info_cur_user_function_create';
import { log_info_cur_user_function_create } from '../Func/Log_info';
import { set_file_functions_create } from '../Func/Set_file';
import { res_send_cur_user_functions_create } from '../Classes/cla_res_send_cur_user_functions_create';
import { sign_mdb_cur_user_function_identity } from '../Func/Sign_identity';
import { get_mdb_cur_user_functions_create } from '../Func/Sign_identity/Func/get_mdb_path_cur_user_functions';
import { prop_cur_req_user_identity } from '../../../../../../../Classes/cla_req_cur_headers_info';
import { get_cur_db_count_for_id } from '../../../../../../../Func/get_mdb_new_id';
/**
 * 当前 用户 创建一个 函数
 */
export const cur_user_create_func: RequestHandler = async (req, res) => {
  let req_info = new req_info_cur_user_function_create(req);

  req_info.id = await get_cur_db_count_for_id(
    get_mdb_cur_user_functions_create(req_info[prop_cur_req_user_identity])
  );

  /**
   * 记录 identity 身份 信息
   */
  sign_mdb_cur_user_function_identity(req_info);

  /**
   * 录入 文件
   */
  set_file_functions_create(req_info);

  /**
   * 记录 log 信息
   */
  log_info_cur_user_function_create(req_info);

  /**
   * 响应 创建 函数 信息
   */
  let res_send = new res_send_cur_user_functions_create();

  res.send(res_send);
};
